<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: datafeed.php 220 2013-09-22 08:02:14Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 220 $
* 	zuletzt geaendert von:	siekiera
* 	Datum:					$Date: 2013-09-22 08:02:14 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

chdir('../..');
include('includes/application_top.php');
require_once(DIR_FS_INC.'inc.get_products_mo_images.php');

$FeedPrice = new price($_SESSION['currency'], $_SESSION['customers_status']['customers_status_id']);

$products = $db->db_query("SELECT
								p.products_id,
								p.products_model,
								p.products_price,
								p.products_image,
								p.products_tax_class_id,
								pd.products_name,
								pd.treepodia_1 AS pt_1,
								pd.treepodia_2 AS pt_2,
								pd.treepodia_3 AS pt_3,
								pd.treepodia_4 AS pt_4,
								pd.treepodia_5 AS pt_5
							FROM
								".TABLE_PRODUCTS." p
								LEFT JOIN ".TABLE_PRODUCTS_DESCRIPTION." AS pd
								ON (pd.products_id = p.products_id AND pd.language_id = '".$_SESSION['languages_id']."')
							WHERE
								p.products_treepodia = '1'
							AND
								p.products_status = '1'
							GROUP BY
								p.products_id
							ORDER BY
								p.products_id ASC");

if($products->_numOfRows) {
	echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";

	echo '<products>'."\n";

	while(!$products->EOF) {

		$cat = $db->db_query("SELECT
									cd.treepodia_1 AS ct_1,
									cd.treepodia_2 AS ct_2,
									cd.treepodia_3 AS ct_3,
									cd.treepodia_4 AS ct_4,
									cd.treepodia_5 AS ct_5
								FROM
									".TABLE_PRODUCTS_TO_CATEGORIES." p2c,
									".TABLE_CATEGORIES_DESCRIPTION." cd
								WHERE
									p2c.products_id = '".$products->fields['products_id']."'
								AND
									cd.categories_id = p2c.categories_id");

		echo "\t".'<product>'."\n";

		# Products ID
		echo "\t\t".'<sku>'.$products->fields['products_id'].'</sku>'."\n";

		# Products Name
		echo "\t\t".'<name>'.$products->fields['products_name'].'</name>'."\n";

		# Preis
		$final_price = $FeedPrice->AddTax($products->fields['products_price'], $FeedPrice->TAX[$products->fields['products_tax_class_id']]);
		echo "\t\t".'<price>'.$final_price.'</price>'."\n";

		# Products URL
		$url = href_link(FILENAME_PRODUCT_INFO, 'products_id='.$products->fields['products_id']);
		echo "\t\t".'<page-url>'.$url.'</page-url>'."\n";

		# Hersteller
		$brand = $db->db_query("SELECT brand_name, brand_image FROM ".TABLE_BRAND." WHERE brand_id = '".$products->fields['products_id']."'");
		if($brand->_numOfRows)
			echo "\t\t".'<brand-name>'.$products->fields['brand_name'].'</brand-name>'."\n";
		if(!empty($brand->fields['brand_image']))
			echo "\t\t".'<brand-logo>'.HTTP_SERVER.DIR_WS_CATALOG.DIR_WS_IMAGES.'brand/'.$products->fields['brand_image'].'</brand-logo>'."\n";

		# Images
		if(!empty($products->fields['products_image']))
			echo "\t\t".'<image>'.HTTP_SERVER.DIR_WS_CATALOG.DIR_WS_POPUP_IMAGES.$products->fields['products_image'].'</image>'."\n";
		$images = get_products_mo_images($products->fields['products_id']);
		if($images) {
			for($i = 0; $i < sizeof($images); $i++) {
				echo "\t\t".'<image>'.HTTP_SERVER.DIR_WS_CATALOG.DIR_WS_POPUP_IMAGES.$images[$i]['image_name'].'</image>'."\n";
				if($i == 8)
			        break;
			}
		}

		$phrase_1 = ( !empty($products->fields['pt_1']) ? $products->fields['pt_1'] : ( !empty($cat->fields['ct_1']) ? $cat->fields['ct_1'] : TREEPODIA_PHRASE_1 ) );
		$phrase_2 = ( !empty($products->fields['pt_2']) ? $products->fields['pt_2'] : ( !empty($cat->fields['ct_2']) ? $cat->fields['ct_2'] : TREEPODIA_PHRASE_2 ) );
		$phrase_3 = ( !empty($products->fields['pt_3']) ? $products->fields['pt_3'] : ( !empty($cat->fields['ct_3']) ? $cat->fields['ct_3'] : TREEPODIA_PHRASE_3 ) );
		$phrase_4 = ( !empty($products->fields['pt_4']) ? $products->fields['pt_4'] : ( !empty($cat->fields['ct_4']) ? $cat->fields['ct_4'] : TREEPODIA_PHRASE_4 ) );
		$phrase_5 = ( !empty($products->fields['pt_5']) ? $products->fields['pt_5'] : ( !empty($cat->fields['ct_5']) ? $cat->fields['ct_5'] : TREEPODIA_PHRASE_5 ) );

		echo "\t\t".'<catch-phrase>'.$phrase_1.'</catch-phrase>'."\n";
		echo "\t\t".'<catch-phrase>'.$phrase_2.'</catch-phrase>'."\n";
		echo "\t\t".'<catch-phrase>'.$phrase_3.'</catch-phrase>'."\n";
		echo "\t\t".'<catch-phrase>'.$phrase_4.'</catch-phrase>'."\n";
		echo "\t\t".'<catch-phrase>'.$phrase_5.'</catch-phrase>'."\n";

		echo "\t".'</product>'."\n";
		$products->MoveNext();
	}
	echo '</products>'."\n";
}
?>